package com.api.shopapi.mapper;

import com.api.shopapi.entity.ServeclassServe;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface ServeclassServeMapper {

    @Insert("insert into serveclass_serve " +
            "(" +
            "ServeclassServeCode, " +
            "ServeclassCode, " +
            "ServeclassName, " +
            "ServeCode, " +
            "ServeName, " +
            "Sort" +
            ") " +
            "VALUES (#{serveclassServe.ServeclassServeCode} ," +
            "#{serveclassServe.ServeclassCode} ," +
            "#{serveclassServe.ServeclassName} ," +
            "#{serveclassServe.ServeCode} ," +
            "#{serveclassServe.ServeName} ," +
            "#{serveclassServe.Sort} )")
    int insert(@Param("serveclassServe") ServeclassServe serveclassServe);

    @Update("update serveclass_serve set " +
            "ServeclassServeCode=#{serveclassServe.ServeclassServeCode} ," +
            "ServeclassCode=#{serveclassServe.ServeclassCode} ," +
            "ServeclassName=#{serveclassServe.ServeclassName} ," +
            "ServeCode=#{serveclassServe.ServeCode} ," +
            "ServeName=#{serveclassServe.ServeName} ," +
            "Sort=#{serveclassServe.Sort}  " +
            "where ServeclassServeCode=#{serveclassServe.ServeclassServeCode}    ")
    int update(@Param("serveclassServe") ServeclassServe serveclassServe);

    @Select("<script>" +
            "select * from serveclass_serve " +
            "where 1=1" +
            "<if test ='serveclassName !=\"\" '>" +
            " and ServeclassName like concat('%',#{serveclassName},'%')" +
            "</if>" +
            "<if test ='serveName !=\"\" '>" +
            " and ServeName like concat('%',#{serveName},'%')" +
            "</if>" +
            " order by Sort asc" +
            "</script>")
    List<ServeclassServe> getPageList(@Param("serveclassName") String serveclassName,
                            @Param("serveName") String serveName);

    @Select("select * from serveclass_serve")
    List<ServeclassServe> getList();

    @Select("select * from serveclass_serve where ServeclassName=#{serveclassName} limit 1 ")
    ServeclassServe getByServeclassName(String serveclassName);

    @Select("select * from serveclass_serve where ServeName=#{serveName} limit 1 ")
    ServeclassServe getByServeName(String serveName);

    @Select("select  * from  serveclass_serve where ServeclassServeCode=#{serveclassServeCode} limit 1 ")
    ServeclassServe getByServeclassServeCode(@Param("serveclassServeCode") String serveclassServeCode);

    @Delete("delete  from serveclass_serve where ServeclassServeCode=#{serveclassServeCode}")
    int delete(@Param("serveclassServeCode") String serveclassServeCode);

}
